import pymysql

# 数据库连接信息
host = "localhost"
user = "root"
password = "123456"
database = "django-web"

# 建立连接
connection = pymysql.connect(
    host=host,
    user=user,
    password=password,
    database=database,
    charset='utf8mb4'
)

try:
    with connection.cursor() as cursor:
        # 查询 sys_user 表前20条数据
        sql = "SELECT * FROM sys_user LIMIT 20"
        cursor.execute(sql)
        results = cursor.fetchall()
        for row in results:
            print(row)
finally:
    connection.close()